***************************************************************************
***************   CLASSIFICATIONS  
***************************************************************************

******** TABLE 1
*** Additional details in PDF file: "Details on OB classifications"
use 2010-2016_ob_data_Williams.dta, clear
drop if ped_extension==1
keep patent_number use_code DS DP
duplicates drop
rename patent_number iprnumber
gen uc=0
replace uc=1 if use_code!=""
destring DS, replace force
destring DP, replace force
gen alt=0
replace alt=1 if DS==1 & DP==1 & uc==1
replace alt=2 if DS==1 & DP==1 & uc==0
replace alt=3 if DS==1 & DP==0 & uc==1
replace alt=4 if DS==1 & DP==0 & uc==0
replace alt=5 if DS==0 & DP==1 & uc==1
replace alt=6 if DS==0 & DP==1 & uc==0
replace alt=7 if DS==0 & DP==0 & uc==1
replace alt=8 if DS==0 & DP==0 & uc==0
keep iprnumber alt
duplicates drop
saveold OB_classifications_2010-2016.dta, replace

use ob_data_2017_2019.dta , clear
drop if ped_extension=="1"
keep patent_number use_code ds dp
replace use_code="1" if use_code!=""
duplicates drop
rename patent_number iprnumber
gen uc=0
replace uc=1 if use_code!=""
gen DS=0
replace DS=1 if ds==1
gen DP=0
replace DP=1 if dp==1
destring DS, replace force
destring DP, replace force
gen alt=0
replace alt=1 if DS==1 & DP==1 & uc==1
replace alt=2 if DS==1 & DP==1 & uc==0
replace alt=3 if DS==1 & DP==0 & uc==1
replace alt=4 if DS==1 & DP==0 & uc==0
replace alt=5 if DS==0 & DP==1 & uc==1
replace alt=6 if DS==0 & DP==1 & uc==0
replace alt=7 if DS==0 & DP==0 & uc==1
replace alt=8 if DS==0 & DP==0 & uc==0
keep iprnumber alt
duplicates drop
saveold OB_classifications_2017-2019.dta, replace


use OB_classifications_2010-2016.dta, clear
append using OB_classifications_2017-2019.dta
keep iprnumber alt
duplicates drop
bys iprnumber: gen kk=_N
tab kk
keep if kk==1
drop kk
label define codes 1 "DS=1 & DP=1 & uc=1" 2 "DS=1 & DP=1 & uc=0" /*
*/3 "DS=1 & DP=0 & uc=1" 4 "DS=1 & DP=0 & uc=0" 5 "DS=0 & DP=1 & uc=1" /*
*/ 6 "DS=0 & DP=1 & uc=0" 7 "DS=0 & DP=0 & uc=1" 8 "DS=0 & DP=0 & uc=0"
label values alt codes
joinby iprnumber using Medtrack_Arti_classified_final.dta, unmatched(both)
tab _merge
keep if _merge==3
drop _merge
tabout alt classification using "asd.tex", c(freq) f(0c 1) style(tex) font(bold) replace




***************************************************************************
***************   LITIGATION   
***************************************************************************
***** TABLE 2

*** DATA Preparation

use ptab_cases.dta, clear
gen date1=date(fillingdate, "YMD")
keep if date1<=date("2019-12-31", "YMD")
bys iprnumber: gen PTAB=_N
keep iprnumber PTAB
duplicates drop
saveold ptab_numbers-up-2019.dta, replace

use LM_short_patent_cases.dta, clear
gen date1=date(filedon, "MDY")
keep if date1>=date("9/16/2011", "MDY")
keep if date1<=date("12/31/2019", "MDY")
bys patent: gen DCT=_N
rename patent iprnumber
keep iprnumber DCT
duplicates drop
saveold dct_numbers_9-16-2011-to-2019.dta, replace


use dct_numbers_9-16-2011-to-2019.dta, clear
joinby iprnumber using ptab_numbers-up-2019.dta, unmatched(both)
drop if iprnumber==""
replace PTAB=0 if PTAB==.
replace DCT=0 if DCT==.
drop _merge
saveold litigated_numbers_new.dta, replace




use litigated_numbers_new.dta, clear
joinby iprnumber using Medtrack_Arti_classified_final_2012_up.dta, unmatched(both)
* This observation is not classified correctly
drop if iprnumber=="7935873"
gen dct=( DCT>0)
gen ptab=(PTAB>0)

**** Table 2 - Litigated OB patents by venue
tab ptab dct if _merge==3
*tabout _merge if _merge>=2 using "asd.tex", c(freq col) f(0c 1) style(tex) font(bold) replace


**** Table 3 - Litigated non-OB patents by venue
tab ptab dct if _merge==1

gen m=_merge
gen OB=(_merge>=2)
gen OB_litigated=(_merge==3)
drop _merge

**** Table 4 - Litigated patents
tab classification m if  OB
*tabout classification m if  OB using "asd1.tex", c(freq) f(0c 1) style(tex) font(bold) replace
*tabout classification m if OB using "asd2.tex", c(col) f(2c 3) style(tex) font(bold) replace


gen PTAB_2=(PTAB>=1)*(PTAB!=.)
gen DCT_2=(DCT>=1)*(DCT!=.)


**** Table 5 - Litigated patents
tab classification m if OB & PTAB_2==1 
*tabout classification m if OB & PTAB_2==1 using "asd.tex", c(freq) f(0c 1) style(tex) font(bold) replace
*tabout classification m if OB & PTAB_2==1 using "asd1.tex", c(col) f(2c 3) style(tex) font(bold) replace

tab classification m if OB & DCT_2==1
*tabout classification m if OB & DCT_2==1 using "asd2.tex", c(freq) f(0c 1) style(tex) font(bold) replace
*tabout classification m if OB & DCT_2==1 using "asd3.tex", c(col) f(2c 3) style(tex) font(bold) replace



joinby iprnumber using OB_continuity_data.dta, unmatched(both)

tab ct m if  OB & classification!=.
*tabout ct m if  OB & classification!=. using "asd1.tex", c(freq) f(0c 1) style(tex) font(bold) replace
*tabout ct m if OB & classification!=. using "asd2.tex", c(col) f(2c 3) style(tex) font(bold) replace

gen C=(con>0)+(cip>0)
gen C2=(C>0)

**** TABLE 6
tab C2 m if  OB & classification!=.
*tabout C2 m if  OB & classification!=. using "asd1.tex", c(freq) f(0c 1) style(tex) font(bold) replace
*tabout C2 m if OB & classification!=. using "asd2.tex", c(col) f(2c 3) style(tex) font(bold) replace



**** TABLE 7
tab C2 m if  OB & PTAB_2==1
tab C2 m if  OB & DCT_2==1



**** TABLE 8
 ***
tab C2 m if  OB & classification==1
*tabout C2 m if  OB & classification==1 using "asd1.tex", c(freq) f(0c 1) style(tex) font(bold) replace
*tabout C2 m if OB & classification==1 using "asd2.tex", c(col) f(2c 3) style(tex) font(bold) replace

tab C2 m if  OB & classification==2
*tabout C2 m if  OB & classification==2 using "asd1.tex", c(freq) f(0c 1) style(tex) font(bold) replace
*tabout C2 m if OB & classification==2 using "asd2.tex", c(col) f(2c 3) style(tex) font(bold) replace

tab C2 m if  OB & classification==3
*tabout C2 m if  OB & classification==3 using "asd1.tex", c(freq) f(0c 1) style(tex) font(bold) replace
*tabout C2 m if OB & classification==3 using "asd2.tex", c(col) f(2c 3) style(tex) font(bold) replace
*/


**** TABLE 9

******* REGRESSION ANALYSIS
use Matched_Covariates_OB_patents.dta
joinby patent_number using OB_patents_2012_and_up_editions.dta, unmatched(both)
tab _merge
keep if _merge==3
drop _merge
rename patent_number iprnumber
joinby iprnumber using litigated_numbers_new.dta, unmatched(both)
tab _merge
keep if _merge!=2
drop if filing_date==.
replace PTAB=0 if PTAB==.
replace DCT=0 if DCT==.
egen ex_art=group(examiner_art_unit)
gen SMALL=(small_entity_indicator=="SMALL")
gen iss_year=year(patent_issue_date)


drop _merge
joinby iprnumber using Medtrack_Arti_classified_final_2012_up.dta, unmatched(both)

duplicates drop

drop _merge
joinby iprnumber using OB_continuity_data.dta, unmatched(both)
gen C=(con>0)+(cip>0)
gen C2=(C>0)
label variable C2 "CiP or Cont"

reg DCT SMALL i.classification C2, r
estimates store a
reg DCT SMALL i.classification C2 i.iss_year, r
estimates store b
reg DCT SMALL i.classification C2 i.iss_year i.ex_art, r
estimates store c

reg PTAB SMALL i.classification C2, r
estimates store d
reg PTAB SMALL i.classification C2 i.iss_year, r
estimates store e
reg PTAB SMALL i.classification C2 i.iss_year i.ex_art, r
estimates store f


*** Table 9:
esttab a b c d e f using Table1_payments.tex, label replace booktabs ar2 keep(SMALL 1.classification 2.classification 3.classification C2)




